
#pragma once

//#include <winsock2.h>
#include "inetaddr.h"

namespace sock {

	class Selector;

	class RawSocket {
	public:
		explicit RawSocket( int sock );
		RawSocket();
		RawSocket( const RawSocket & other );
		RawSocket & operator=( const RawSocket & other );

		~RawSocket();

		// common
		void swap( RawSocket &other );

		// client sock func.
		void connect( const InetAddr & addr );
		int read( void *buf, int len );
		void write( const void *buf, int len );

		// server sock func.
		void bind( const InetAddr & addr );
		void listen( int maxconn );
		void listen();
		RawSocket accept();

		// state checking func.
		bool isconnected() const;

	protected:
		friend class Selector;

	private:
		struct Impl;
		Impl * _pimpl;
		unsigned *_pcounter;
	};

}
